<?php

namespace app\store\service;

use app\store\model\UserGrade;

class StoreUserGradeService
{

    public static function getStoreUserGradeList($keyword)
    {   
        $store_id = session('store_id');

        $query = UserGrade::withOutField('desc')->where('store_id',$store_id);

        if(!empty($keyword)){
            $query->where('grade_name',$keyword);
        }

        $storeUserGrades = $query->select();
        
        return  $storeUserGrades;
        
    }


    public static function getStoreUserGradeOptions()
    {   
        $store_id = session('store_id');

        $storeUserGradeOptions = UserGrade::field('id,grade_name')
                                          ->where(['store_id' => $store_id, 'status' => 1,'is_default' => 0])
                                          ->select();

        if($storeUserGradeOptions->isEmpty()){
            return [];
        }
        
        return   $storeUserGradeOptions->toArray();
        
    }

    public static function findStoreUserGrade($id)
    {
        $storeUserGrade = UserGrade::withOutField('create_time,update_time,delete_time')->find($id);

        return $storeUserGrade;
        
    }

    
}